package com.it.myd.bean.box.world;

import com.it.myd.bean.main.User;
import com.it.myd.help.PrefixLoader;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Random;

public abstract class Item {

    private String id;
    private String code;
    private String name;
    private String type;
    private String region;//部位
    private String state;//0-制造中 1-制作完成 2-装备中 3-耐久没了
    private Prefix prefix;
    private Intensify intensify;
    private Ability ability;
    private int maxHp;
    private int hp;
    private int needTime;
    private int time;
    private int maxUsetime;
    private int usetime;
    private List<Material> needMaters;
    private int count;
    private int level;
    private String isStack;//1 可以堆叠 0 不可以
    private String createtime;
    private User createuser;
    private User oweruser;
    private User useuser;
    public void createdItem(){
        SimpleDateFormat sdf= new SimpleDateFormat("yyyyMMddHHmmss");
        String createtime = sdf.format(System.currentTimeMillis());
        Random random = new Random();
        int randomNumber = random.nextInt(999) + 1;
        String formattedNumber = String.format("%03d", randomNumber);
        this.setCode(this.getName()+"_"+createtime+formattedNumber);
        PrefixLoader prefixLoader = new PrefixLoader();
        this.setPrefix(prefixLoader.randomPrefix(this));
    }
    public abstract Ability useItem(Ability a,MyObject obj);
    public void addHp(int addhp){
        if(hp+addhp>=maxHp){
            hp = maxHp;
        }else{
            hp = hp + addhp;
        }
    }
    public Ability getAllAbility(MyObject obj){
        Ability a = this.ability;
        if(prefix != null){
            a = ability.addAbility(prefix.getAbility());
        }
        if(intensify != null){
            a = ability.addAbility(intensify.getAbility());
        }
        if(obj != null){
            a = useItem(a,obj);
            ReduceAurable();
        }
        return a;
    }

    public void ReduceAurable(){
        if(hp > 0){
            hp = hp - 1;
        }
        if(hp <= 0){
            state = "3";
        }
    }

    public Ability getAbility() {
        return ability;
    }

    public void setAbility(Ability ability) {
        this.ability = ability;
    }

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public int getMaxUsetime() {
        return maxUsetime;
    }

    public void setMaxUsetime(int maxUsetime) {
        this.maxUsetime = maxUsetime;
    }

    public int getUsetime() {
        return usetime;
    }

    public void setUsetime(int usetime) {
        this.usetime = usetime;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public Intensify getIntensify() {
        return intensify;
    }

    public void setIntensify(Intensify intensify) {
        this.intensify = intensify;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Prefix getPrefix() {
        return prefix;
    }

    public void setPrefix(Prefix prefix) {
        this.prefix = prefix;
    }

    public int getMaxHp() {
        return maxHp;
    }

    public void setMaxHp(int maxHp) {
        this.maxHp = maxHp;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public int getNeedTime() {
        return needTime;
    }

    public void setNeedTime(int needTime) {
        this.needTime = needTime;
    }

    public List<Material> getNeedMaters() {
        return needMaters;
    }

    public void setNeedMaters(List<Material> needMaters) {
        this.needMaters = needMaters;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public String getIsStack() {
        return isStack;
    }

    public void setIsStack(String isStack) {
        this.isStack = isStack;
    }

    public String getCreatetime() {
        return createtime;
    }

    public void setCreatetime(String createtime) {
        this.createtime = createtime;
    }

    public User getCreateuser() {
        return createuser;
    }

    public void setCreateuser(User createuser) {
        this.createuser = createuser;
    }

    public User getOweruser() {
        return oweruser;
    }

    public void setOweruser(User oweruser) {
        this.oweruser = oweruser;
    }

    public User getUseuser() {
        return useuser;
    }

    public void setUseuser(User useuser) {
        this.useuser = useuser;
    }
}
